<include file="Public:header_content" />
<link href="/Public/plugin/gb312/css/plugins/datapicker/datepicker3.css" rel="stylesheet" type="text/css"/>
<link href="/Public/plugin/gb312/css/plugins/summernote/summernote.css"  rel="stylesheet">
<link href="/Public/plugin/gb312/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">

<div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">

                    <div class="ibox-content">
                        <div class="ibox-tools">
                            <a class="back-link" href="javascript:history.go(-1);">
                                <i class="fa fa-chevron-left"></i>
                            </a>
                        </div>
                        <form id="add-book-form" class="form-horizontal" method="post" action="__SELF__">
                            <div class="form-group search_val">
                                <label class="col-sm-2 control-label">书本名称</label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <input type="text" name="book_name" value="<{$book_name}>" class="form-control">
                                        <span class="input-group-btn">
                                            <button id="search_name" type="button" class="btn btn-primary">搜索</button>
                                        </span>
                                        <input type="hidden" name="book_id" value="<{$book_id}>" >
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">卷名篇名</label>
                                <div class="col-sm-5">
                                    <input type="text" name="piece_name" class="form-control"> <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group article_name">
                                <label class="col-sm-2 control-label">章节名称</label>
                                <div class="col-sm-6">
                                    <input type="text" name="article_name" placeholder="章节名称" class="form-control">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">更新时间</label>
                                <div class="col-sm-2 input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" name="create_time" class="form-control" value="2017-3-11" readonly />
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-14">

                                        <div class="ibox-content no-padding" id="eg">
                                            <div class="click2edit wrapper"></div>

                                        </div>

                                </div>
                            </div>
                            <input name="content" type="hidden" value="" />
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" id="submit" type="submit">保存</button>
                                    <button class="btn btn-white" type="submit">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>


<include file="Public:footer_content" />
<script src="/Public/plugin/gb312/js/plugins/datapicker/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="/Public/plugin/gb312/js/plugins/summernote/summernote.min.js" ></script>
<script src="/Public/plugin/gb312/js/plugins/summernote/summernote-zh-CN.js" ></script>

<script type="text/javascript">

    var flag = null;

    $(function(){
        $(".click2edit").summernote({
            //height: 300,
            minHeight: 300,
            onImageUpload: function(files,editor, welEditable) {
                         sendFile(files[0],editor, welEditable);
                },
            lang:"zh-CN",
            focus:true
        });



        var e="<i class='fa fa-times-circle'></i> ";
        $("#add-book-form").validate({
			rules:{
				book_name:{
                    required:!0,
                    remote: {
                        url: "<{:U('Book/checkBookName')}>",     //后台处理程序
                        type: "post",               //数据发送方式
                        dataType: "json",           //接受数据格式
                        data: {                     //要传递的数据
                            mobile:function(){
                                return $('input[name="book_id"]').val();
                            }
                        }
                    }
                },
                article_name:{
                    required:!0,
                    remote: {
                        url: "<{:U('Book/checkArtcileRepeat')}>",//后台处理程序
                        type: "post",               //数据发送方式
                        dataType: "json",           //接受数据格式
                        data: {                     //要传递的数据
                            book_id:function(){
                                return $('input[name="book_id"]').val();
                            }
                        }
                    }
                }
			},
			messages:{
				book_name:{
                    required:e+"请输入书本名称",
                    remote:e+"该书本名称不存在"
                },
                article_name:{
                    required:e+"请输入章节名称",
                    remote:e+"该书章节名称已存在"
                }
			}
		});

        //保存
        $('#submit').click(function(){
            content=$(".click2edit").code();
            $('input[name="content"]').val(encodeURIComponent(content));
            $('form').submit();
        });

    });


        //图片上传
        function sendFile(file,editor,welEditable) {
            formData = new FormData();
            formData.append("file", file);
            //console.log(formData);
            $.ajax({
                url: "<{:U('Public/UploadImg')}>",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                success: function(url) {
                      editor.insertImage(welEditable, url);
                }
            });
        }

</script>